#!/usr/bin/env python
#coding:utf-8

import urllib
from sgmllib import SGMLParser
import re

class URLLister(SGMLParser):
    def reset(self):
        SGMLParser.reset(self)
        self.data = []
        self.q = 0

    def start_td(self, attrs):
        #pass
        self.q = 1
        
    def end_td(self):
        #pass
        self.q = 0

    def handle_data(self, data):
        if self.q:
            self.data.append(data)

def main():
    p = URLLister()
    html = urllib.urlopen('http://www.weather.com.cn/weather/101270501.shtml').read()
    data = p.feed(html)
    p.close()
    #print len(p.data)
    s = p.data
    mylist = [x.strip() for x in s if x.strip()]
    #print mylist

    for d in mylist:
        #list中含有大量的\n，需要re对其进行检查，非\n打印。
        print ''.join(d),
        
if __name__ == '__main__':
    main()
